package com.cx.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ToolUtil {
    /**
     * 将日期转换为指定个是返回
     * @param date
     * @param format   如yyyy-MM-dd hh:mm:ss
     * @return
     */
    public static String fortmatDate(Date date, String format){
        if(date == null) {
            return "";
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        String str = sdf.format(date);
        return str;
    }


    public static Date transmitString2Date(String dateStr, String format){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        try {
            Date date = simpleDateFormat.parse(dateStr);
            return date;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

}
